#include "DynArray.h"

#define VSF_TEX0		0
#define VSF_TEX1		1
#define VSF_TEX2		2

namespace Scenic
{
namespace Renderer
{
struct COMMON_VERTEX
{
	float x;
	float y;
	float z;
	int diffuse;
	float tex[1][2];
};

struct VERTEX_INFO
{
	int index;
	double p[2];
	int diffuse;
	double tex[2][2];
};

struct Rect
{
	int left;
	int top;
	int right;
	int bottom;
};

class VertexStore
{
	Context *context;
	Affine2 *tm;
	int type;
	int vertexSize;
	Rect clipRect;
	DynArray<char> vertices;
	DynArray<int> indices;
	DynArray<VERTEX_INFO> block;
	int numVertices;
	double default_tu2, default_tv2;
public:
	VertexStore(int type, Context *context, Affine2 *tm, ClipArea *clip = 0);

	void init(int type, Context *context, Affine2 *tm, ClipArea *clip);
	void setType(int type);
	int addVertex(double x, double y, int diffuse);
	int addVertex(double x, double y, int diffuse, double tu1, double tv1);
	int addVertex(double x, double y, int diffuse, double tu1, double tv1, double tu2, double tv2);
	void addTriangle(int a, int b, int c);
	void setDefaultTex2(double tu2, double tv2);

	void endBlock();
	void draw();
	void empty();
private:
	void clipTriangle(int *ti, int stage);
	void processTriangle(int *vi);
};
}
}
